<template>
  <div class="GLawRegulationDetail">
    <div class="detail" v-if="type=='detail'">
      <div class="head">
        <div class="title">{{detail.title}}</div>
        <div class="time-box">
          <div>颁布单位：{{ detail.publish_unit }}</div>
          <div>颁布时间：{{ detail.publish_date }}</div>
          <div>发布时间：{{ detail.mtime }}</div>
          <div>最近修改时间：{{ detail.mtime }}</div>
        </div>
      </div>
      <div class="html ql-editor" v-html="detail.content_preview"></div>
      <div class="btn-box">
        <zy-button @click="back">返回</zy-button>
      </div>
    </div>
    <zyInfoPanel :title="type=='add'?'新增法律法规':'编辑法律法规'" :showUnfoldButton="false" class="baseInfo" v-else>
      <div class="baseBox">
        <div class="form">
          <div class="form-item">
            <div class="input-box">
              <div class="input-name required">标题</div>
              <zy-input placeholder="请输入标题" maxlength="200" v-model="detail.title"></zy-input>
            </div>
          </div>
          <div class="form-item">
            <div class="input-box">
              <div class="input-name required">颁布单位</div>
              <zy-input placeholder="输入来源" maxlength="200" v-model="detail.publish_unit"></zy-input>
            </div>
          </div>
          <div class="form-item">
            <div class="input-box">
              <div class="input-name required">颁布时间</div>
              <datePicker type="date" v-model="detail.publish_date"></datePicker>
            </div>
          </div>
          <div class="form-item">
            <div class="input-box input-box-base">
              <div class="input-name">正文</div>
              <zyEditor class="editor" v-model="detail.content_preview"></zyEditor>
            </div>
          </div>
          <div class="form-item">
            <div class="input-box">
              <div class="input-name"></div>
              <div class="btn-box">
                <zy-button @click="back">取消</zy-button>
                <zy-button type="primary" @click="submit">提交</zy-button>
              </div>
            </div>
          </div>
        </div>
      </div>
    </zyInfoPanel>
  </div>
</template>

<script>
	import datePicker from "../../../../components/datePicker/index"

	export default {
		name: "GLawRegulationDetail",
		props: {},
		data() {
			return {
				type: '',
				article_id: '',
				detail: {
					title: '',
					publish_unit: '',
					publish_date: '',
					mtime: '',
					content_preview: ''
				}
			};
		},
		computed: {
			postData() {
				let data = {...this.detail, article_id: this.article_id || ''};
				return data;
			}
		},
		watch: {},
		components: {datePicker},
		methods: {
			//获取数据
			getData() {
				this.$axios.post(this.$api.admin_detailArticle, {article_id: this.article_id}).then(res => {
					let {code, msg, data} = res;
					if (code == 200) {
						this.detail = data || {};
						this.detail.publish_date = this.type == 'edit' ? new Date(data.publish_date).getTime() : data.publish_date
					} else {
						this.$message.error(msg);
					}
				})
			},
			back(isRefresh) {
				this.$toRoutePath({
					path: '/article_list',
					that: this,
					name: 'GLawRegulationList',
					params: {isRefresh}
				})
			},
			submit() {
				this.$axios.post(this.$api.admin_saveArticle, {...this.postData}).then(res => {
					let {code, msg} = res;
					if (code == 200) {
						this.$message.success("保存成功!");
						this.back(true)
					} else {
						this.$message.error(msg);
					}
				})
			},
		},
		mounted() {
			this.type = this.$route.query.type || '';
			this.article_id = this.$route.query.article_id || '';
			if (this.type == 'detail' || this.type == 'edit')
				this.getData();
		},
		created() {
		}
	}
</script>

<style scoped lang="less" src="@/style/government/infoInteractionManage/lawRegulationDetail/index.less">

</style>
